﻿#region Usings
using System.Collections.Generic;
using BK.BL;
using BK.Entities;
using Lib.Data.CriteriaRoutine;
using Lib.Utils.Collections.TreeRoutine;
using Lib.Utils.StrUtils;
#endregion

namespace BK.WebSite.Accounting.Autocomplete
{
	/// <summary>
	/// Summary description for GetCategories
	/// </summary>
	public class GetCategories : BaseAutocompleteHandler<CategoryEntity, Categories>
	{
		#region Instance Methods
		protected override Criteria CreateCriteria()
		{
			return null;
		}

		protected override AutocompleteEntity[] DoConvertEntities(CategoryEntity[] entities)
		{
			List<ITreeNodeEntity> reorderedEntities = TreeNodeListBuilderUtils.ReorderTreeNodeEntities(entities);

			AutocompleteEntity[] result = new AutocompleteEntity[entities.Length];
			for (int i = 0; i < result.Length; i++)
			{
				result[i] = new AutocompleteEntity
				            	{
									Text = StrUtility.BuildString("&nbsp;&nbsp;&nbsp;&nbsp;", ((CategoryEntity)reorderedEntities[i]).NestingLevel) + ((CategoryEntity)reorderedEntities[i]).Name,
									Value = ((CategoryEntity)reorderedEntities[i]).Id.ToString(),
									FullName = ((CategoryEntity)reorderedEntities[i]).FullName,
				            	};
			}
			return result;
		}

		private void Rebuild(CategoryEntity[] categoryEntities)
		{
			
		}
		#endregion
	}
}